import { Link } from '@brillout/docpress'

Setting `process.env.NODE_ENV` is a <Link href="#see-also">widespread convention</Link> to tell tools whether your app is being run in development or production.

> It's crucial to respect the following convention, otherwise many tools will misbehave (such as React).

In development:

- Make sure `process.env.NODE_ENV` is one of these values: `[undefined, 'development', 'dev', '']`.
- If you use a server, make sure to add Vite's server middleware. (See <Link href="/renderPage#usage" />.)

In production (and staging):

- Make sure `process.env.NODE_ENV` is a value different than `[undefined, 'development', 'dev', '']`.
  > Note that:
  > - Upon starting your server in production, make sure to set `process.env.NODE_ENV`. (E.g. `$ NODE_ENV='production' node server/index.js`.)
  > - Upon building (`$ vite build`), Vite automatically sets `process.env.NODE_ENV` to `'production'`.
  > - Upon manually triggering pre-rendering (<Link href="/command-prerender">`$ vike prerender`</Link>), Vike automatically sets `process.env.NODE_ENV` to `'production'`.
- If you use a server, make sure you don't add Vite's server middleware: it isn't needed in production and would unnecessarily bloat your production server.


## See also

 - [Node.js Docs - The difference between development and production](https://nodejs.org/en/learn/getting-started/nodejs-the-difference-between-development-and-production#:~:text=You%20can%20signal%20Node.js%20that%20you%20are%20running%20in%20production%20by%20setting%20the%20NODE_ENV%3Dproduction%20environment%20variable.)
   > While the `process.env.NODE_ENV` convention was introduced by Node.js, it's used by tools regardless of whether you use Node.js. Thus, make sure to follow the convention even in non-Node.js environments.
 - [Stack Overflow - What is NODE_ENV and how to use it in Express?](https://stackoverflow.com/questions/16978256/what-is-node-env-and-how-to-use-it-in-express/16979503#16979503:~:text=NODE_ENV%20specifically%20is%20used%20(by%20convention)%20to%20state%20whether%20a%20particular%20environment%20is%20a%20production%20or%20a%20development%20environment.)
